package cn.ac.iie.di.ban.nmpp.metastore;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class TableSe2DBRule {

    String ruleName;
    String ruleContent;
    String mqName;
    String dbType;
    String connStr;
    String userName;
    String password;
    String tableName;
    int parallelSize;
    int batchSize;
    List<Column> columnSet = new ArrayList();
    String sGroup;

    public TableSe2DBRule(String pRuleName, String pRuleContent, String pMQName, String pDBType, String pJDBCURL, String pUserName, String pPassword, String pTableName, int pParallelSize, int pBacthSize, String pSGroup) {
        this.ruleName = pRuleName;
        this.ruleContent = pRuleContent;
        this.mqName = pMQName;
        this.dbType = pDBType;
        this.connStr = pJDBCURL;
        this.userName = pUserName;
        this.password = pPassword;
        this.tableName = pTableName;
        this.parallelSize = pParallelSize;
        this.batchSize = pBacthSize;
        this.sGroup = pSGroup;
    }

    public void parseColumSet(String pColumnSetStr) {
        String[] columns = pColumnSetStr.split(":");
        for (String column : columns) {
            String[] columnItems = column.split(",");
            this.columnSet.add(new Column(columnItems[0], Integer.parseInt(columnItems[1]),columnItems[2],columnItems[3]));
        }
        Collections.sort(this.columnSet);
    }

    public String getMqName() {
        return this.mqName;
    }

    public String getTableName() {
        return this.tableName;
    }

    public String getDbType() {
        return this.dbType;
    }

    public List<Column> getColumnSet() {
        return this.columnSet;
    }

    public String getConnStr() {
        return this.connStr;
    }

    public String getUserName() {
        return this.userName;
    }

    public String getPassword() {
        return this.password;
    }

    public String getRuleName() {
        return this.ruleName;
    }

    public int getParallelSize() {
        return this.parallelSize;
    }

    public int getBatchSize() {
        return this.batchSize;
    }

    public String getsGroup() {
        return sGroup;
    }

    public class Column implements Comparable {

        String columnName;
        int columnIdx;
        String columnType;
        String rocketColumnName;

        public Column(String pColumnName, int pColumnIdx,String pColumnType,String pRocketColumnName) {
            this.columnName = pColumnName;
            this.columnIdx = pColumnIdx;
            this.columnType = pColumnType;
            this.rocketColumnName=pRocketColumnName;
        }

        public String getColumnName() {
            return this.columnName;
        }

        public int getColumnIdx() {
            return this.columnIdx;
        }
        public String getColumnType() {
            return this.columnType;
        }
        public String getRocketColumnName() {
            return this.rocketColumnName;
        }

        public int compareTo(Object o) {
            Column otherColumn = (Column) o;
            return this.columnIdx - otherColumn.columnIdx;
        }
    }
}